// 回车搜索留言
function onKeyDownStayWord(event) {
    var e = event || window.event || arguments.callee.caller.arguments[0];
    if (e && e.keyCode == 13) {
        var content = $.trim($(".searchContentStayWord").val());
        if (content == null || content.length != 0) {
            window.location.href = "/stayWordManage/searchStayWord?content=" + content;
        } else {
            alert("搜索条件不能为空呦");
        }
    }
}

// 按钮搜索留言
$(".searchBtnStayWord").on("click", function () {
    var content = $.trim($(".searchContentStayWord").val());
    if (content == null || content.length != 0) {
        window.location.href = "/stayWordManage/searchStayWord?content=" + content;
    } else {
        alert("搜索条件不能为空呦");
    }
});

// 删除留言
function deleteStayWord(staywordId) {
    $("#deleteStayWordModal").modal({
        keyboard: false
    });
    $("#deleteStayWordBtn").on("click", function () {
        if (staywordId != null && staywordId.length != null) {
            $.ajax({
                type: "POST",
                url: "/stayWordManage/deleteStayWord",
                data: {staywordId: staywordId},
                dataType: "json",
                success: function (data) {
                    if (data.result == "success") {
                        window.location.reload();
                    } else {
                        alert("BUG：删除留言失败");
                    }
                },
                error: function () {
                    $(".article-message").html("ajax 服务器错误").css({"color": "red"});
                }
            });
        }
    });
}

// 回复留言
function replyStayWord(staywordId, staywordEmail, staywordMessage, replyContent) {
    $("#replyStayWordModal").modal({
        keyboard: false
    });
    $(".stayWordMessage").html(staywordMessage);
    $("#replyStayWordBtn").on("click", function () {
        var replyContent = $(".replyContent").val();
        if (staywordId != null && staywordId.length != null) {
            if (staywordEmail != null && staywordEmail.length != null) {
                if (replyContent != null && replyContent.length != null) {
                    $.ajax({
                        type: "POST",
                        url: "/stayWordManage/replyStayWord",
                        data: {staywordId: staywordId, staywordEmail: staywordEmail, replyContent: replyContent},
                        dataType: "json",
                        success: function (data) {
                            if (data.result == "success") {
                                window.location.reload();
                            }
                        },
                        error: function () {
                            $(".stayword-message").html("ajax 服务器错误").css({"color": "red"});
                        }
                    });
                } else {
                    $(".stayword-message").html("请输入回复内容").css({"color": "red"});
                }
            } else {
                $(".stayword-message").html("回复的邮箱未找到").css({"color": "red"});
            }
        } else {
            $(".stayword-message").html("回复的ID未找到").css({"color": "red"});
        }
    });
}